import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from tableCounter import Ui_MainWindow
from PyQt5.QtCore import pyqtSignal, Qt, QThread, QDate, QDateTime, QTime, QRegExp
from MyThread import TimeCountThread
import time


class MyMainWindow(QMainWindow, Ui_MainWindow):
	helpSignal = pyqtSignal(str)

	def __init__(self, parent=None):
		super(MyMainWindow, self).__init__(parent)
		self.setupUi(self)
		self.initUI()

	def initUI(self):
		print(self.tableWidget.rowCount())
		self.startBtn.clicked.connect(self.startCounter)

	def startCounter(self):
		self.startBtn.setEnabled(False)
		# for i in range(self.tableWidget.rowCount()):
		self.TimeCount = TimeCountThread()
		time1 = int(self.tableWidget.item(0, 2).text(), 10)
		time2 = int(self.tableWidget.item(0, 3).text(), 10)
		self.TimeCount.data = time1 * 60 + time2
		self.TimeCount.updateStartTime.connect(self.startTimeDisplay)
		# self.TimeCount[i].updateRunTime.connect(self.leftTimeDisplay)
		# self.TimeCount[i].updateEnd.connect(self.timeOver)
		self.TimeCount.start()

	def setItem(var: tuple):  # 用于向jcb表格填写内容
		i = var[0]  # 行
		j = var[1]  # 列
		s = var[2]  # 值
		table = MainWindow_ui.tableWidget_2
		if j != 6:
			table.setItem(i, j, QtWidgets.QTableWidgetItem(str(s)))
		else:
			table.cellWidget(i, 6).setValue(s)  # 这是个进度条来的

	def startTimeDisplay(self,data):
		self.tableWidget.item(0, 1).setText(data)

	def Print_Job():
		rowcol = len(Jcb_Ready_List) + len(Jcb_Wait_List)
		print(rowcol)
		for i in range(0, rowcol):
			MainWindow_ui.tableWidget_2.showRow(i)
		for i in range(0, len(Jcb_Ready_List)):
			jcb = Jcb_Ready_List[i]
			table = MainWindow_ui.tableWidget_2
			MainThread.signal2emit((i, 0, jcb.Name))
			MainThread.signal2emit((i, 1, jcb.Arrival_time))
			MainThread.signal2emit((i, 2, jcb.Need_memory))
			MainThread.signal2emit((i, 3, jcb.Need_time))
			MainThread.signal2emit((i, 4, jcb.Already_execution_time))
			MainThread.signal2emit((i, 5, jcb.Wait_time))
			MainThread.signal2emit((i, 6, 100 - jcb.Need_time / (jcb.Already_execution_time + jcb.Need_time) * 100))


if __name__ == "__main__":
	app = QApplication(sys.argv)
	win = MyMainWindow()
	win.show()
	sys.exit(app.exec_())
